using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugar;

namespace SqlSugarLearing.Model
{
    public class YTDepartMent
    {
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public string DID { get; set; }
        public string DName { get; set; }
        public string DPID { get; set; }

        public bool ValidFlag { get; set; }

        [SqlSugar.SugarColumn(IsIgnore = true)]
        public List<YTDepartMent> Childs { get; set; }

        public List<YTDepartMent> GetAllChildIds()
        {
            return TreeSearch(this);
        }

        private List<YTDepartMent> TreeSearch(YTDepartMent node)
        {
            List<YTDepartMent> list = new List<YTDepartMent>() { node };
            foreach (var item in node.Childs)
            {
                list.AddRange(TreeSearch(item));
            }
            return list;
        }
    }
}